﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;

namespace MapViewer
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App : Application
	{
		private void Application_Startup(object sender, StartupEventArgs e)
		{
			if (MapViewer.Properties.Settings.Default.Recent == null)
				MapViewer.Properties.Settings.Default.Recent = new System.Collections.Specialized.StringCollection();
			System.Collections.Specialized.StringCollection recent = MapViewer.Properties.Settings.Default.Recent;
			RecentItemsCollection items = Resources["RecentItems"] as RecentItemsCollection;
			foreach (var item in recent)
			{
				items.Add(Model.RecentItem.Parse(item));
			}
		}

		private void Application_Exit(object sender, ExitEventArgs e)
		{
			System.Collections.Specialized.StringCollection recent = MapViewer.Properties.Settings.Default.Recent;
			RecentItemsCollection items = Resources["RecentItems"] as RecentItemsCollection;
			recent.Clear();
			foreach (var item in items)
			{
				recent.Add(item.Definition);
			}
			MapViewer.Properties.Settings.Default.Save();
		}
	}

	public class RecentItemsCollection : System.Collections.ObjectModel.ObservableCollection<Model.RecentItem> { }
}
